/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Gsb.Andro;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import android.view.View;
import android.widget.ImageView;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import modele.DAO;

/**
 *
 * @author plasalmonie
 */
public class FicheMed extends Activity {

    private String leNum = "";

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        //on va chercher la vue
        setContentView(R.layout.fichemed);

        Button call = (Button) findViewById(R.id.buttonCall);
        Button sms = (Button) findViewById(R.id.buttonSms);

        //Information Mdecin
        TextView nom = (TextView) findViewById(R.id.nom);
        TextView prenom = (TextView) findViewById(R.id.prenom);
        TextView adresse = (TextView) findViewById(R.id.adresse);
        TextView numero = (TextView) findViewById(R.id.num);
        TextView spe = (TextView) findViewById(R.id.spe);

        //Image Carte
        //ImageView img = (ImageView) findViewById(R.id.imageMap);

        Intent inter = getIntent();
        String leNom = inter.getStringExtra("leNom");
        String lePrenom = inter.getStringExtra("lePrenom");
        String Adresse = inter.getStringExtra("adr");
        this.leNum = inter.getStringExtra("leNum");
        String laSpe = inter.getStringExtra("laSpe");

        nom.setText("Nom :  " + leNom);
        prenom.setText("Prenom :    " + lePrenom);
        adresse.setText("Adresse :  " + Adresse);
        numero.setText("Numéro :    " + leNum);

        if (laSpe.equals("")) {
            spe.setText("Spécialité : Généraliste");
        } else {
            spe.setText("Spécialité :   " + laSpe);
        }

        String url = "http://maps.googleapis.com/maps/api/staticmap?center=" + Adresse + "&zoom=13&size=600x300&maptype=roadmap&sensor=false";
        try {
            ImageView i = (ImageView) findViewById(R.id.imageMap);
            Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(url).getContent());
            i.setImageBitmap(bitmap);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        };

//Drawable b = DAO.LoadImageFromWebOperations(url);        
        //img.setImageDrawable(b);
        call.setOnClickListener(new View.OnClickListener() {
            public void onClick(View arg0) {
                Intent callIntent = new Intent(Intent.ACTION_CALL);
                callIntent.setData(Uri.parse("tel:" + leNum));
                startActivity(callIntent);
            }
        });
        sms.setOnClickListener(new View.OnClickListener() {
            public void onClick(View arg0) {
                Intent smsIntent = new Intent(Intent.ACTION_VIEW);
                smsIntent.setData(Uri.parse("sms:" + leNum));
                startActivity(smsIntent);
            }
        });

    }

}
